﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Workbench.PresentationModel;

namespace SharedGenomics.Workbench.Tests.PresentationModel
{
    [TestClass]
    public class DataColumnSchemaTests
    {
        private DataColumnSchema schema;

        [TestInitialize]
        public void Setup()
        {
            this.schema = new DataColumnSchema();
        }

        [TestMethod]
        public void ConstructorTest()
        {
            DataColumnSchema s = new DataColumnSchema();
            Assert.AreEqual(0, s.Count);
        }

        [TestMethod]
        public void AddTest_Valid_Count()
        {
            this.schema.Add(new DataGridColumnInfo("header", "prop", typeof(int)));
            Assert.AreEqual(1, this.schema.Count);
        }

        [TestMethod]
        public void AddTest_Valid_IndexUpdated()
        {
            DataGridColumnInfo info = new DataGridColumnInfo("header", "prop", typeof(int));
            this.schema.Add(info);

            Assert.AreEqual(0, info.Index);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void AddTest_Invalid_Null()
        {
            this.schema.Add(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddTest_Invalid_DuplicatePropertyName()
        {
            this.schema.Add(new DataGridColumnInfo("header", "prop", typeof(int)));
            this.schema.Add(new DataGridColumnInfo("headerText", "prop", typeof(string)));
        }

        [TestMethod]
        public void IndexerTest_Valid_Index()
        {
            DataGridColumnInfo info = new DataGridColumnInfo("header", "propertyName", typeof(int));
            this.schema.Add(info);

            Assert.AreEqual(info, this.schema[0]);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void IndexerTest_Invalid_IndexNegative()
        {
            var info = this.schema[-1];
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void IndexerTest_Invalid_IndexTooLarge()
        {
            var info = this.schema[0];
        }

        [TestMethod]
        public void IndexerTest_Valid_PropertyName()
        {
            DataGridColumnInfo info = new DataGridColumnInfo("header", "propertyName", typeof(int));
            this.schema.Add(info);

            Assert.AreEqual(info, this.schema["propertyName"]);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void IndexerTest_Invalid_PropertyNameNull()
        {
            var info = this.schema[null];
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void IndexerTest_Invalid_PropertyNameNotFound()
        {
            var info = this.schema["invalidPropertyName"];
        }
    }
}
